import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { createVNode } from 'vue';
import { Modal } from 'ant-design-vue';
export const useHandleData = (api, params, message, confirmType = "warning") => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '操作确认',
      content: `确定${message}?`,
      onOk: async () => {
        try {
          const res = await api(params);
          if (!res) {
            throw new Error('操作失败');
          }
          if (res.data && res.data.success) {
            Modal.success({
              content: `${message}成功!`
            });
            resolve(true);
          } else {
            const errorMsg = res.data?.message || '未知错误';
            Modal.error({
              content: errorMsg
            });
            reject(false);
          }
        } catch (error) {
          console.error('操作异常:', error);
          Modal.error({
            content: '操作异常，请重试'
          });
          reject(false);
        }
      },
      onCancel: () => {
        reject(false);
      },
      okText: '确定',
      cancelText: '取消',
    });
  });
};